/**
 * 
 */
package co.gov.medellin.sdep.sisdep.regulacion.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.regulacion.exception.FeriaDecDetalleItemException;
import co.gov.medellin.sdep.sisdep.regulacion.exception.FeriaDecDetalleItemRuntimeException;
import co.gov.medellin.sdep.sisdep.regulacion.exception.descriptor.FeriaDecDetalleItemMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.FeriaDecDetalleItem;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IFeriaDecDetalleItemDAOT;

/**
 * @author Usuario
 *
 */
public class FeriaDecDetalleItemServiceImpl extends BaseService implements IFeriaDecDetalleItemService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IFeriaDecDetalleItemDAOT feriaDecDetalleItemDAO;

	/**
	 * 
	 */
	public FeriaDecDetalleItemServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(FeriaDecDetalleItem feriaDecDetalleItem) throws FeriaDecDetalleItemException {
		try{
			feriaDecDetalleItem.setUsuarioCrea(getPrincipalUser());
			feriaDecDetalleItem.setFechaCrea(new Date());
			getFeriaDecDetalleItemDAO().insert(feriaDecDetalleItem);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new FeriaDecDetalleItemException(new FeriaDecDetalleItemMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new FeriaDecDetalleItemException(new FeriaDecDetalleItemMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(FeriaDecDetalleItem feriaDecDetalleItem) throws FeriaDecDetalleItemException {
		try{
			feriaDecDetalleItem.setUsuarioModifica(getPrincipalUser());
			feriaDecDetalleItem.setFechaModifica(new Date());
			getFeriaDecDetalleItemDAO().update(feriaDecDetalleItem);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new FeriaDecDetalleItemRuntimeException(new FeriaDecDetalleItemMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new FeriaDecDetalleItemRuntimeException(new FeriaDecDetalleItemMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(FeriaDecDetalleItem feriaDecDetalleItem) throws FeriaDecDetalleItemException {
		try {
			feriaDecDetalleItem.setUsuarioModifica(getPrincipalUser());
			feriaDecDetalleItem.setFechaModifica(new Date());
			getFeriaDecDetalleItemDAO().delete(feriaDecDetalleItem);
		}catch (Exception e) {
			Object [] infoError = {
			};
			throw new FeriaDecDetalleItemRuntimeException(new FeriaDecDetalleItemMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, FeriaDecDetalleItem feriaDecDetalleItem) throws FeriaDecDetalleItemException {
		try{
			//return getFeriaDecDetalleItemDAO().getAllFeriaDecDetalleItemPaginated(start, max, criteria);
			return getFeriaDecDetalleItemDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new FeriaDecDetalleItemRuntimeException(new FeriaDecDetalleItemMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	
	/**
	 * @return 
	 * 
	 */
	public final List loadByAgno(int start,int max, FeriaDecDetalleItem feriaDecDetalleItem) throws FeriaDecDetalleItemException {
		try{
			//return getFeriaDecDetalleItemDAO().getAllFeriaDecDetalleItemPaginated(start, max, criteria);
			return getFeriaDecDetalleItemDAO().loadByAgno(feriaDecDetalleItem);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new FeriaDecDetalleItemRuntimeException(new FeriaDecDetalleItemMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final FeriaDecDetalleItem get(long id) throws FeriaDecDetalleItemException {
		try{
			return getFeriaDecDetalleItemDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new FeriaDecDetalleItemRuntimeException(new FeriaDecDetalleItemMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public IFeriaDecDetalleItemDAOT getFeriaDecDetalleItemDAO() {
		return feriaDecDetalleItemDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setFeriaDecDetalleItemDAO(IFeriaDecDetalleItemDAOT feriaDecDetalleItemDAO) {
		this.feriaDecDetalleItemDAO = feriaDecDetalleItemDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
